package com.spring.component.easyexcel;


import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.text.ParseException;
import java.util.Locale;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
import com.alibaba.excel.read.builder.ExcelReaderSheetBuilder;
import com.spring.component.easyexcel.converter.AutoConverter;
import com.spring.component.easyexcel.listener.DemoDataListener;
import com.spring.component.easyexcel.listener.NoModelDataListener;

public class ExcelReadTest {

  private static final String FILE_PATH =
      "G:\\工作\\香港项目\\主副卡\\V3\\应急系统\\应急配置\\序列\\0416对比结果\\ins1_sequences.xls";

  public static void main(String[] args) {
    // noModelRead();
    simpleRead();
    // test();
  }

  public static void noModelRead() {
    ExcelReaderBuilder builder = EasyExcel.read(FILE_PATH, new NoModelDataListener());
    ExcelReaderSheetBuilder sheetBuilder = builder.registerConverter(new AutoConverter()).sheet();
    // 异步读取
    sheetBuilder.doRead();
  }

  public static void simpleRead() {
    String filename = "G:\\tmp\\Demo1.xlsx";
    // DemoData.class指定每行数据的收集方式
    EasyExcel.read(filename, DemoData.class, new DemoDataListener()).sheet().doRead();
  }

  public static void test() {
    String str = "65.21%";
    String format = "#.##%";
    DecimalFormat decimalFormat = new DecimalFormat(format, DecimalFormatSymbols.getInstance(Locale.CHINA));
    decimalFormat.setRoundingMode(RoundingMode.FLOOR);
    decimalFormat.setParseBigDecimal(true);
    Number value = null;
    try {
      value = decimalFormat.parse(str);
    } catch (ParseException e) {
      e.printStackTrace();
    }
    System.out.println(value);
  }

}
